﻿using EnqueteMobile.Repository.Base;
using EnqueteMobile.Repository.Database.EntityFramework.Repositories;
using EnqueteMobile.Repository.Database.Model;
using EnqueteMobile.Repository.Database.RepositoriesInterfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EnqueteMobile.Repository.Database.EntityFramework
{
    public class MobilePollUnitOfWork : IMobilePollUnitOfWork
    {
        public void Commit()
        {
            context.SaveChanges();
        }

        public void Dispose()
        {
            if (context != null) { context.Dispose(); }
            GC.SuppressFinalize(this);
        }

        MobilePollContext context;
        public MobilePollUnitOfWork()
        {
            context = new MobilePollContext();
        }

        public MobilePollUnitOfWork(String connectionName)
        {
            context = new MobilePollContext(connectionName);
        }

        private IMessageSubjectRepository assuntoMensagemRepository;
        public IMessageSubjectRepository MessageSubjectRepository
        {
            get
            {
                if(assuntoMensagemRepository == null)
                {
                    assuntoMensagemRepository = new MessageSubjectRepository(context);
                }
                return assuntoMensagemRepository;
            }
        }

        private ICityRepository cityRepository;
        public ICityRepository CityRepository
        {
            get
            {
                if (cityRepository == null)
                {
                    cityRepository = new CityRepository(context);
                }
                return cityRepository;
            }
        }

        private IClientRepository clientRepository;
        public IClientRepository ClientRepository
        {
            get
            {
                if(clientRepository == null)
                {
                    clientRepository = new ClientRepository(context);
                }
                return clientRepository;
            }
        }

        private IClientConfigurationRepository clientConfigurationRepository;
        public IClientConfigurationRepository ClientConfigurationRepository
        {
            get
            {
                if(clientConfigurationRepository == null)
                {
                    clientConfigurationRepository = new ClientConfigurationRepository(context);
                }
                return clientConfigurationRepository;
            }
        }

        private ICommunicationControlRepository communicationControlRepository;
        public ICommunicationControlRepository CommunicationControlRepository
        {
            get
            {
                if(communicationControlRepository == null)
                {
                    communicationControlRepository = new CommunicationControlRepository(context);
                }
                return communicationControlRepository();
            }
        }

        private IAddressRepository addressRepository;
        public IAddressRepository AddressRepository
        {
            get
            {
                if(addressRepository == null)
                {
                    addressRepository = new AddressRepository(context);
                }
                return addressRepository;
            }
        }

        private ILogAppRepository logAppRepository;
        public ILogAppRepository LogAppRepository
        {
            get
            {
                if(logAppRepository == null)
                {
                    logAppRepository = new LogAppRepository(context);
                }
                return logAppRepository;
            }
        }

        private ILogBDRepository logBDRepository;
        public ILogBDRepository LogBDRepository
        {
            get
            {
                if(logBDRepository == null)
                {
                    logBDRepository = new LogBDRepository(context);
                }
                return logBDRepository;
            }
        }

        private IPersonRepository pessoaRepository;
        public IPersonRepository PersonRepository
        {
            get
            {
                if(pessoaRepository == null)
                {
                    pessoaRepository = new PersonRepository(context);
                }
                return pessoaRepository;
            }
        }

        public IResourceRepository ResourceRepository
        {
            get { throw new NotImplementedException(); }
        }

        public IIdDocumentRepository IdDocumentRepository
        {
            get { throw new NotImplementedException(); }
        }

        public ISystemRepository SystemRepository
        {
            get { throw new NotImplementedException(); }
        }

        private ITelephoneRepository telephoneRepository;
        public ITelephoneRepository TelephoneRepository
        {
            get { throw new NotImplementedException(); }
        }


        public IAppActionTypeRepository AppActionTypeRepository
        {
            get { throw new NotImplementedException(); }
        }

        private IAddressTypeRepository addressTypeRepository;
        public IAddressTypeRepository AddressTypeRepository
        {
            get
            {
                if(addressTypeRepository == null)
                {
                    addressTypeRepository = new AddressTypeRepository(context);
                }
                return addressTypeRepository;
            }
        }

        public IObjectTypeRepository ObjectTypeRepository
        {
            get { throw new NotImplementedException(); }
        }

        public IObjectRightTypeRepository ObjectRightTypeRepository
        {
            get { throw new NotImplementedException(); }
        }

        public IObjectResourceTypeRepository ObjectResourceTypeRepository
        {
            get { throw new NotImplementedException(); }
        }

        private IResourceTypeRepository tipoRecursoRepository;
        public IResourceTypeRepository ResourceTypeRepository
        {
            get
            {
                if(tipoRecursoRepository == null)
                {
                    tipoRecursoRepository = new ResourceTypeRepository(context);
                }
                return tipoRecursoRepository;
            }
        }

        public ITelephoneTypeRepository TelephoneTypeRepository
        {
            get { throw new NotImplementedException(); }
        }

        public IBallotTitleRepository BallotTitleRepository
        {
            get { throw new NotImplementedException(); }
        }

        private IFederalUnitRepository unidadeFederativaRepository;
        public IFederalUnitRepository FederalUnitRepository
        {
            get
            {
                if (unidadeFederativaRepository == null)
                {
                    unidadeFederativaRepository = new FederalUnitRepository(context);
                }
                return unidadeFederativaRepository;
            }
        }

        private IUserRepository userRepository;
        public IUserRepository UserRepository
        {
            get
            {
                if(userRepository == null)
                {
                    userRepository = new UserRepository(context);
                }
                return userRepository;
            }
        }
    }
}